package webjoch.methods;

import webjoch.Main;
import webjoch.wrappers.Room;

import com.rsbuddy.script.methods.Players;
import com.rsbuddy.script.wrappers.Area;
import com.rsbuddy.script.wrappers.Tile;

/**
 * 
 * @author Webjoch
 *
 */
public class Rooms {
	/**
	 * Get a room
	 * @param location the location that the room contains
	 * @return a room from which contains the given location
	 */
	public static Room getRoom(Tile location){
		if (location == null) return null;
		double x = ((double) (location.getX() - Main.getDungeon().getBaseLocation().getX() + 7));
		double y = ((double) (location.getY() - Main.getDungeon().getBaseLocation().getY() + 7));
		int x1 = (int) (x - Math.floor(x/16) * 16);
		int y1 = (int) (y - Math.floor(y/16) * 16);
		Area roomArea = new Area(new Tile(location.getX() - x1, location.getY() - y1), new Tile(location.getX() + 15 - x1, location.getY() + 15 - y1));
		return new Room(roomArea);
	}
	
	/**
	 * Get the room where the local player is standing
	 * @return the local room
	 */
	public static Room getLocalRoom(){
		return getRoom(Players.getLocal().getLocation());
	}
	
	/**
	 * Get the base room
	 * @return the base room
	 */
	public static Room getBase(){
		Tile baseLocation = Main.getDungeon().getBaseLocation();
		Area baseArea = new Area(new Tile(baseLocation.getX() - 7, baseLocation.getY() - 7), new Tile(baseLocation.getX() + 8, baseLocation.getY() + 8));
		return new Room(baseArea);
	}
}
